package o;

import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import o.fvb.d;

public final class fvf {
    @Nullable
    public final fvb ˊ;
    @Nullable
    public final fus ˋ;

    public static class a {
        private long ʻ;
        private Date ʼ;
        private String ʽ;
        final fus ˊ;
        private String ˋ;
        final long ˎ;
        final fvb ˏ;
        private int ͺ = -1;
        private Date ॱ;
        private String ॱˊ;
        private long ॱॱ;
        private Date ᐝ;

        public a(long j, fus o_fus, fvb o_fvb) {
            this.ˎ = j;
            this.ˊ = o_fus;
            this.ˏ = o_fvb;
            if (o_fvb != null) {
                this.ॱॱ = o_fvb.ॱˊ();
                this.ʻ = o_fvb.ˏॱ();
                fui ʼ = o_fvb.ʼ();
                int ˋ = ʼ.ˋ();
                for (int i = 0; i < ˋ; i++) {
                    String ॱ = ʼ.ॱ(i);
                    String ˋ2 = ʼ.ˋ(i);
                    if ("Date".equalsIgnoreCase(ॱ)) {
                        this.ॱ = fvs.ॱ(ˋ2);
                        this.ˋ = ˋ2;
                    } else if ("Expires".equalsIgnoreCase(ॱ)) {
                        this.ʼ = fvs.ॱ(ˋ2);
                    } else if ("Last-Modified".equalsIgnoreCase(ॱ)) {
                        this.ᐝ = fvs.ॱ(ˋ2);
                        this.ʽ = ˋ2;
                    } else if ("ETag".equalsIgnoreCase(ॱ)) {
                        this.ॱˊ = ˋ2;
                    } else if ("Age".equalsIgnoreCase(ॱ)) {
                        this.ͺ = fvr.ˏ(ˋ2, -1);
                    }
                }
            }
        }

        public fvf ˊ() {
            fvf ˎ = ˎ();
            if (ˎ.ˋ == null || !this.ˊ.ᐝ().ʼ()) {
                return ˎ;
            }
            return new fvf(null, null);
        }

        private fvf ˎ() {
            long j = 0;
            if (this.ˏ == null) {
                return new fvf(this.ˊ, null);
            }
            if (this.ˊ.ॱॱ() && this.ˏ.ʻ() == null) {
                return new fvf(this.ˊ, null);
            }
            if (!fvf.ˎ(this.ˏ, this.ˊ)) {
                return new fvf(this.ˊ, null);
            }
            fuc ᐝ = this.ˊ.ᐝ();
            if (ᐝ.ˎ() || ˊ(this.ˊ)) {
                return new fvf(this.ˊ, null);
            }
            long toMillis;
            fuc ͺ = this.ˏ.ͺ();
            long ॱ = ॱ();
            long ˏ = ˏ();
            if (ᐝ.ˏ() != -1) {
                ˏ = Math.min(ˏ, TimeUnit.SECONDS.toMillis((long) ᐝ.ˏ()));
            }
            if (ᐝ.ᐝ() != -1) {
                toMillis = TimeUnit.SECONDS.toMillis((long) ᐝ.ᐝ());
            } else {
                toMillis = 0;
            }
            if (!(ͺ.ʽ() || ᐝ.ʻ() == -1)) {
                j = TimeUnit.SECONDS.toMillis((long) ᐝ.ʻ());
            }
            if (ͺ.ˎ() || ॱ + toMillis >= r4 + ˏ) {
                String str;
                String str2;
                if (this.ॱˊ != null) {
                    str = "If-None-Match";
                    str2 = this.ॱˊ;
                } else if (this.ᐝ != null) {
                    str = "If-Modified-Since";
                    str2 = this.ʽ;
                } else if (this.ॱ == null) {
                    return new fvf(this.ˊ, null);
                } else {
                    str = "If-Modified-Since";
                    str2 = this.ˋ;
                }
                o.fui.a ˎ = this.ˊ.ॱ().ˎ();
                fux.ˏ.ˋ(ˎ, str, str2);
                return new fvf(this.ˊ.ʽ().ˏ(ˎ.ˊ()).ॱ(), this.ˏ);
            }
            d ʽ = this.ˏ.ʽ();
            if (toMillis + ॱ >= ˏ) {
                ʽ.ˏ("Warning", "110 HttpURLConnection \"Response is stale\"");
            }
            if (ॱ > HwAccountConstants.CHECK_SITE_COUNTRY_DURATION && ˋ()) {
                ʽ.ˏ("Warning", "113 HttpURLConnection \"Heuristic expiration\"");
            }
            return new fvf(null, ʽ.ˏ());
        }

        private long ˏ() {
            fuc ͺ = this.ˏ.ͺ();
            if (ͺ.ˏ() != -1) {
                return TimeUnit.SECONDS.toMillis((long) ͺ.ˏ());
            }
            long time;
            if (this.ʼ != null) {
                if (this.ॱ != null) {
                    time = this.ॱ.getTime();
                } else {
                    time = this.ʻ;
                }
                time = this.ʼ.getTime() - time;
                if (time <= 0) {
                    time = 0;
                }
                return time;
            } else if (this.ᐝ == null || this.ˏ.ॱ().ˏ().ˋॱ() != null) {
                return 0;
            } else {
                if (this.ॱ != null) {
                    time = this.ॱ.getTime();
                } else {
                    time = this.ॱॱ;
                }
                time -= this.ᐝ.getTime();
                if (time > 0) {
                    return time / 10;
                }
                return 0;
            }
        }

        private long ॱ() {
            long j = 0;
            if (this.ॱ != null) {
                j = Math.max(0, this.ʻ - this.ॱ.getTime());
            }
            if (this.ͺ != -1) {
                j = Math.max(j, TimeUnit.SECONDS.toMillis((long) this.ͺ));
            }
            return (j + (this.ʻ - this.ॱॱ)) + (this.ˎ - this.ʻ);
        }

        private boolean ˋ() {
            return this.ˏ.ͺ().ˏ() == -1 && this.ʼ == null;
        }

        private static boolean ˊ(fus o_fus) {
            return (o_fus.ˋ("If-Modified-Since") == null && o_fus.ˋ("If-None-Match") == null) ? false : true;
        }
    }

    fvf(fus o_fus, fvb o_fvb) {
        this.ˋ = o_fus;
        this.ˊ = o_fvb;
    }

    public static boolean ˎ(fvb o_fvb, fus o_fus) {
        switch (o_fvb.ˊ()) {
            case 200:
            case 203:
            case 204:
            case 300:
            case 301:
            case 308:
            case ResponseBean.NOT_FOUND /*404*/:
            case 405:
            case 410:
            case 414:
            case 501:
                break;
            case 302:
            case 307:
                if (o_fvb.ˋ("Expires") == null && o_fvb.ͺ().ˏ() == -1 && !o_fvb.ͺ().ˊ() && !o_fvb.ͺ().ˋ()) {
                    return false;
                }
            default:
                return false;
        }
        return (o_fvb.ͺ().ॱ() || o_fus.ᐝ().ॱ()) ? false : true;
    }
}
